package com.xlhj.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xlhj.dubbo.api.service.UserApiService;
import com.xlhj.dubbo.api.vo.UserVo;
import com.xlhj.dubbo.entity.SysUser;
import com.xlhj.dubbo.service.SysUserService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author: lcj
 * @Date: 2020/11/20 9:49
 * @Description: 对外提供用户查询接口实现类
 * @Version: 0.0.1
 */
@Service
@DubboService(version = "${provider.service.version}")
public class UserApiServiceImpl implements UserApiService {

    @Autowired
    private SysUserService userService;

    /**
     * 根据用户名和密码查询用户信息
     * @param username
     * @param password
     * @return
     */
    @Override
    public UserVo selectUserByUserNameAndPassword(String username, String password) {
        QueryWrapper<SysUser> wrapper = new QueryWrapper<SysUser>();
        wrapper.eq("user_name", username);
        wrapper.eq("password", password);
        SysUser user = userService.getOne(wrapper);
        UserVo vo = new UserVo();
        vo.setId(user.getId());
        vo.setUserName(user.getUserName());
        vo.setRealName(user.getRealName());
        vo.setPassword(user.getPassword());
        vo.setSex(user.getSex());
        vo.setAvatar(user.getAvatar());
        return vo;
    }
}
